// -----------------------------------------------------------
// Game Framework
// Copyright © 2024-2024 deadcycle. All rights reserved.
// Homepage: https://deadcycle.gitee.io
// Feedback: deadcycle@163.com
// -----------------------------------------------------------

using UnityEngine;

namespace UIWidget
{
    public partial class ScrollRectBase
    {
        /// <summary>
        /// 滚动视图的Cell单元格数据。
        /// </summary>
        protected class CellData
        {
            private bool m_RectIsDirty;
            private Rect m_Rect;
            private RectTransform m_Target;
            private CellBase m_CellScript;

            /// <summary> rect 是否需要更新。 </summary>
            public bool RectIsDirty { set => m_RectIsDirty = value; get => m_RectIsDirty; }

            public Rect Rect => m_Rect;

            /// <summary> Cell单元数据对应的目标对象。 </summary>
            public RectTransform Target { get => m_Target; set => m_Target = value; }

            /// <summary> Cell单元数据对应的组件脚本。 </summary>
            public CellBase CellScript { get => m_CellScript; set => m_CellScript = value; }

            public CellData()
            {
                m_RectIsDirty = false;
                m_Rect = default;
                m_Target = null;
                m_CellScript = null;
            }

            public void Initialize()
            {
                m_RectIsDirty = true;
                m_Rect = default;
                m_Target = null;
                m_CellScript = null;
            }

            /// <summary>
            /// 清理关联性的数据。
            /// </summary>
            public void ClearAssociatedData()
            {
                m_Target = null;
                m_CellScript = null;
            }

            public void Clear()
            {
                m_RectIsDirty = false;
                m_Rect = default;
                m_Target = null;
                m_CellScript = null;
            }

            /// <summary>
            /// 更新Rect区域
            /// </summary>
            public void SetRect(float x, float y, float width, float height)
            {
                m_Rect.Set(x, y, width, height);
                m_RectIsDirty = false;
            }
        }
    }
}